# Copyright (c) 2019 Wladislaw Wagner (Vitasystems GmbH), Pablo Pazos (Hannover Medical School).
#
# This file is part of Project EHRbase
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



*** Settings ***
Documentation   Contribution Integration Tests
...
...     Alternative flow 6: commit CONTRIBUTIONS deleting a COMPOSITION
...
...     Preconditions:
...         An EHR with known ehr_id exists, and OPTs should be loaded for each case.
...
...     Flow:
...         1. Invoke commit CONTRIBUTION service with an existing ehr_id and a valid VERSION<COMPOSITION>,
...            that reference existing OPTs in the system.
...         2. The result should be positive, returning the version id for the created VERSION
...         3. Invoke commit CONTRIBUTION service with an existing ehr_id and a valid VERSION<COMPOSITION>
...            that should have the same template_id as the one used in 1.,
...            change_type = deleted and preceding_version_uid = version id returned in 2.,
...            and should reference existing OPTs in the system.
...         4. The result should be positive and the returned version id should reflect it is a new version
...            of an existing contribution (e.g. v2), and that should be deleted.
...
...     Postconditions:
...         There will be two VERSIONS of the same COMPOSITION in the EHR with ehr_id, the VERSIONED_OBJECT
...         should be logically deleted (has COMPOSITION service should return false).
Metadata        TOP_TEST_SUITE    CONTRIBUTION

Resource        ../../_resources/keywords/composition_keywords.robot
Resource        ../../_resources/keywords/contribution_keywords.robot
Resource        ../../_resources/keywords/admin_keywords.robot
Suite Setup     Set Library Search Order For Tests

#Suite Setup  startup SUT
# Test Setup  start openehr server
# Test Teardown  restore clean SUT state
#Suite Teardown  shutdown SUT

Force Tags    refactor



*** Test Cases ***
Alternative flow 6: commit CONTRIBUTIONS deleting a COMPOSITION

    Upload OPT    minimal/minimal_admin.opt
    create EHR
    commit CONTRIBUTION (JSON)    minimal/minimal_admin.contribution.json
    check response: is positive - returns version id
    commit CONTRIBUTION - with preceding_version_uid (JSON)    minimal/minimal_admin.contribution.deleted.deleted.json

    check response: is positive - contribution has new version
    check change_type of new version is    deleted

    [Teardown]    Run Keywords    (admin) delete ehr      AND     (admin) delete all OPTs
